<?php
/*
 * Created on 23 mars 2009
 * Created by Ludovic Reenaers
 * lreenaers@hotmail.com 
 */
 class ViewUser extends View{
 	function logout($bool){
 		$content.='<META HTTP-EQUIV="Refresh" CONTENT="4; URL='.$_SESSION["controler"].'/show/Homepage">';
 		$this->setContent($content);
 	}
 	function forgotPws($page){
 		$this->setContent("forgotPws");
 	}
 	function login($bool){
 		if ($bool){
 			$content= "user logged in ! Hello ".$_SESSION["USER_BEAN"]->getPrenom().",".$_SESSION["USER_BEAN"]->getNom();
 		}else{
 			$content.='<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$_SESSION["controler"].'/showLogin/User">';
 			//$content.="voila";
 		}
 		$this->setContent($content);
 	}
 	function showLogin($page){
		$generator = new LoginFormGenerator($this->translator,null);
		$generator->addChild(new ThirdFailureCaptchaGenerator($this->translator,null));
		$this->setContent($generator->dump());
 	}
	function showForm($page){
		$arr_month= Array("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juiller","Août","Septembre","Octobre","Novembre","Décembre");
		$content="";
		
		if($_SESSION["formHasErr"]==true){
			if($_SESSION["formErr"]==""){
				$content .='<div class="error">&nbsp l\'Utilisateur existe! &nbsp</div>';
			}else{
				$content .='<div class="error">&nbsp Erreur de format: '.$_SESSION["formErr"].' &nbsp</div>';
			}
		}
		
		$content.='<div id="formBorder">'."\n";
			$content.='<div id="formAlign">';
			
		$content .= '<form ACCEPT-CHARSET="UTF-8" name="CreateUser" action="/brahma/php/index.php/registerUser/User" method="post">'."\n";
			$content.= '<table class="userFormTable"><tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Nom : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["nom"].'" type="text" name="nom" class="userFormInput nom"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Prénom : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["prenom"].'" type="text" name="prenom" class="userFormInput prenom"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Pseudo : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["pseudo"].'" type="text" name="pseudo" class="userFormInput pseudo"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> E-mail : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["email"].'" type="text" name="email" class="userFormInput email"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Rue : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["rue"].'" type="text" name="rue" class="userFormInput rue"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Numero : </th><td class="userFormTd">';
					$content.=' <input value="'.$_SESSION["formArray"]["numero"].'" type="text" name="numero" class="userFormInput numero"> </td></tr>'."\n";
					$content.= '<tr class="userFormTr"><th class="userFormTh"> boite : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["boite"].'" type="text" name="boite" class="userFormInput boite"> </td>'."\n";		
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Code Postal : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["cp"].'" type="text" name="cp" class="userFormInput cp"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Ville : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["ville"].'" type="text" name="ville" class="userFormInput ville"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Pays : </th><td class="userFormTd"> <input value="'.$_SESSION["formArray"]["pays"].'" type="text" name="pays" class="userFormInput pays"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Langue : </th><td class="userFormTd" > <select name="langue" class="userFormSelect langue">'."\n";
				foreach($_SESSION["langues"] as $langue){
					if ($_SESSION["formArray"]["langue"]==$langue->getId() or $langue->getId()==$_SESSION["langueid"]){
						$content.= ' <option selected="selected" value="'.$langue->getId().'" class="userFormOption"> '.$langue->getAbr().' </option>'."\n";
					}else{
						$content.= ' <option value="'.$langue->getId().'" class="userFormOption"> '.$langue->getAbr().' </option>'."\n"; 
					}
				}
				$content.= '</select></td>'."\n";
			$content.= '</tr>'."\n";
			
			$content.= '<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Date de naissance : </th>'."\n";
				$content.= '<td class="userFormTd" colspan="5"> '."\n";
					$content.='<table class="innerTable"><tr>'."\n";
						$content.= '<td class="obligatoire">'."\n";
							$content.='<select name="day" class="userFormSelect day">'."\n";
							for($i=1;$i<32;$i++){
								
								if($i==$_SESSION["formArray"]["day"]){
									$content.='<option selected="selected" value="'.$i.'" class="userFormOption">'.$i.'</option>'."\n";
								}else{
									$content.='<option value="'.$i.'" class="userFormOption">'.$i.'</option>'."\n";	
								}
								
							}
							$content.='</select>'."\n";
						$content.= '</td>'."\n";
						$content.= '<td class="obligatoire"><select name="month" class="userFormSelect month">'."\n";
						for($i=0;$i<count($arr_month);$i++){
							if($i+1==$_SESSION["formArray"]["month"]){
								$content.='<option selected="selected" value="'.($i+1).'" class="userFormOption">'.$arr_month[$i].'</option>'."\n";
							}else{
								$content.='<option value="'.($i+1).'" class="userFormOption">'.$arr_month[$i].'</option>'."\n";							
							}
						}

						$content.='</select></td>'."\n";
						$content.= '<td class="obligatoire"><select name="year" class="userFormSelect year">'."\n";
						for($i=1950;$i<date('Y');$i++){
							
							if($i==$_SESSION["formArray"]["year"]){
								$content.='<option selected="selected" value="'.$i.'" class="userFormOption">'.$i.'</option>'."\n";
							}else{
								$content.='<option value="'.$i.'" class="userFormOption">'.$i.'</option>'."\n";
							}
						}
						$content.='</select></td>'."\n";
					$content.= '</tr></table>'."\n";
				$content.= '</td>'."\n";
			$content.= '</tr>'."\n";
			$content.='<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Mot de passe : </th>'."\n";
				$content.= '<td class="userFormTd" > <input type="password" name="pws" value="" class="userFormInput pws"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.='<tr class="userFormTr">'."\n";
				$content.= '<th class="userFormTh"> Confirmation : </th><td class="userFormTd" > <input type="password" name="confirm" value="" class="userFormInput confirm"> </td>'."\n";
			$content.= '</tr>'."\n";
			$content.='<tr class="userFormTr">'."\n";
				$content.= '<td class="userFormTd" colspan="2" align="right"><input type="submit" value="Enregistrer"></td>'."\n";
			$content.= '</tr>'."\n";
		$content.= '</table>'."\n";
		
		$content.= '</form>'."\n";
		
		$content.='</div></div>'."\n";
		$this->setContent($content);
	}
	function registerUser($userBean){
		$content="";
		if($userBean == null){
			$content.='<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$_SESSION["controler"].'/showForm/User">';
		}else{
			$content .='<div class="message">&nbsp l\'Utilisateur a été créé! &nbsp</div>';
			unset($_SESSION["formErr"]);
			unset($_SESSION["formHasErr"]);
			unset($_SESSION["formArray"]);
			//$_SESSION["USER_BEAN"]=$userBean;
		}
		$this->setContent($content);
	}
	
 }
?>
